package com.yiyahui.project.erp.controller;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import com.yiyahui.framework.aspectj.lang.annotation.Log;
import com.yiyahui.framework.aspectj.lang.enums.BusinessType;
import com.yiyahui.project.erp.domain.YiyaChargeProject;
import com.yiyahui.project.erp.service.IYiyaChargeProjectService;
import com.yiyahui.framework.web.controller.BaseController;
import com.yiyahui.framework.web.domain.AjaxResult;
import com.yiyahui.common.utils.poi.ExcelUtil;
import com.yiyahui.framework.web.page.TableDataInfo;

/**
 * 收费项目Controller
 * 
 * @author yiyahui
 * @date 2020-05-12
 */
@Api("收费项目")
@RestController
@RequestMapping("/erp/project")
public class YiyaChargeProjectController extends BaseController
{
    @Autowired
    private IYiyaChargeProjectService yiyaChargeProjectService;
 
    /**
     * 查询收费项目列表
     */
    @ApiOperation("查询收费项目列表")
    @PreAuthorize("@ss.hasPermi('erp:project:list')")
    @GetMapping("/list")
    public TableDataInfo list(YiyaChargeProject yiyaChargeProject)
    {
        startPage();
        List<YiyaChargeProject> list = yiyaChargeProjectService.selectYiyaChargeProjectList(yiyaChargeProject);
        return getDataTable(list);
    }

    /**
     * 导出收费项目列表
     */
    @ApiOperation("导出收费项目列表")
    @PreAuthorize("@ss.hasPermi('erp:project:export')")
    @Log(title = "收费项目", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(YiyaChargeProject yiyaChargeProject)
    {
        List<YiyaChargeProject> list = yiyaChargeProjectService.selectYiyaChargeProjectList(yiyaChargeProject);
        ExcelUtil<YiyaChargeProject> util = new ExcelUtil<YiyaChargeProject>(YiyaChargeProject.class);
        return util.exportExcel(list, "project");
    }

    /**
     * 获取收费项目详细信息
     */
    @ApiOperation("获取收费项目详细信息")
    @ApiImplicitParam(name = "id", value = "主键id", required = true, dataType = "Long", paramType = "path")
    @PreAuthorize("@ss.hasPermi('erp:project:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yiyaChargeProjectService.selectYiyaChargeProjectById(id));
    }

    /**
     * 新增收费项目
     */
    @ApiOperation("新增收费项目")
    @ApiImplicitParam(name = "yiyaChargeProject", value = "${tableComment}", dataType = "YiyaChargeProject")
    @PreAuthorize("@ss.hasPermi('erp:project:add')")
    @Log(title = "收费项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YiyaChargeProject yiyaChargeProject)
    {
        return toAjax(yiyaChargeProjectService.insertYiyaChargeProject(yiyaChargeProject));
    }

    /**
     * 修改收费项目
     */
    @ApiOperation("修改收费项目")
    @ApiImplicitParam(name = "yiyaChargeProject", value = "${tableComment}", dataType = "YiyaChargeProject")
    @PreAuthorize("@ss.hasPermi('erp:project:edit')")
    @Log(title = "收费项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YiyaChargeProject yiyaChargeProject)
    {
        return toAjax(yiyaChargeProjectService.updateYiyaChargeProject(yiyaChargeProject));
    }

    /**
     * 删除收费项目
     */
    @ApiOperation("删除收费项目")
    @ApiImplicitParam(name = "ids", value = "主键id数组", required = true, dataType = "Long[]", paramType = "path")
    @PreAuthorize("@ss.hasPermi('erp:project:remove')")
    @Log(title = "收费项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yiyaChargeProjectService.deleteYiyaChargeProjectByIds(ids));
    }

    /**
     * 根据id列表查询收费项目列表
     */
    @ApiOperation("根据id列表查询收费项目列表")
    @PostMapping("/list/by/ids/")
    public TableDataInfo list(@RequestBody List<YiyaChargeProject> yiyaChargeProjects)
    {
        List<YiyaChargeProject> list = yiyaChargeProjectService.selectByIds(yiyaChargeProjects.stream().map(YiyaChargeProject::getId).collect(Collectors.toList()));
        return getDataTable(list);
    }
}
